<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .wancheng{
            text-decoration: line-through;
            color: gray;
        }
    </style>
</head>
<body>
    <div id="app">
        <h1>任务列表</h1>
        <p>任务总数：{{arr.length}}；还有：{{sum()}} 未完成；【<span @click="clear">完成</span>】</p>
        <ul>
            <li v-for="(abc,index) in arr" :key="index" :class="{wancheng:abc.isFinsh}">
                <input type="checkbox" v-model="abc.isFinsh" @click="wancheng(index)"/>
                <span v-if="!abc.isEdit" @click="edit(index)">{{abc.name}}</span>
                <input v-else type="text" v-model="abc.name" @blur="update(index)"/>
            </li>
        </ul>
        <input type="text" id="name" v-model="name"/> <input type="button" value="添加" @click="add"/>
    </div>
</body>
</html>
<script src="js/vue.min.js"></script>
<script>
    var app=new Vue({
        el:"#app",
        data:{
            arr:[
                {name:"第一个任务",isFinsh:false,isEdit:false},
                {name:"第二个任务",isFinsh:false,isEdit:false},
                {name:"第三个任务",isFinsh:false,isEdit:false},
                {name:"第四个任务",isFinsh:false,isEdit:false}
            ],
            name:""
        },
        methods:{
            add:function(){
                this.arr.push({name:this.name,isFinsh:false,isEdit:false});
                this.name="";
            },
            wancheng:function(index){
                this.arr[index].isFinsh=!this.arr[index].isFinsh;
            },
            sum:function(){
                var count=0;

                for(var i=0;i<this.arr.length;i++){
                    if(this.arr[i].isFinsh==false){
                        count++;
                    }
                }

                return count;
            },
            clear:function(){
                this.arr=this.arr.filter(item=>{
                    return item.isFinsh==false;
                })
            },
            edit:function(index){
                this.arr[index].isEdit=true;
            },
            update:function(index){
                this.arr[index].isEdit=false;
            }
        }
    });
</script>